
#include "env_dev.h"
#include "uart.h"
//http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc
//#define BAUDRATE 38400

void uart_init()
{
    uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(16*BAUDRATE) - 1);
     
    UBRRH = (uint8_t) (ubrr>>8);
    UBRRL = (uint8_t) (ubrr);
   
    // UART Receiver und Transmitter anschalten
    // Data mode 8N1, asynchron
    UCSRB = _BV(RXEN) | _BV(TXEN);
    UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);

    // Flush Receive-Buffer
    do
    {
        uint8_t dummy;
        (void) (dummy = UDR);
    }
    while (UCSRA & _BV(RXC));
}
